<?php


namespace App\Http\Controllers\Api;
use App\Http\Controllers\BaseController;
use App\Models\Category;
use Dingo\Api\Http\Request;

class CategoryController extends BaseController
{

    public function index(Request $request) {
        $this->validate($request, [
            'type' => 'required|in:1,2'
        ]);
        $type = $request->input('type');
        $users = Category::with('child')->type($type)->where('parent_id', 0)->orderBy("id", "asc")
            ->paginate(\request('per_page', 999));
        return $this->paginate($users);
    }
}

